package thread;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: xiaotutu
 * Date: 2025-02-19
 * Time: 19:52
 */

//单例模式 (饿汉模式)

class Singleton {

    private static Singleton instance = new Singleton();

    public static Singleton getInstance() {
        return instance;
    }
    // 做出一个限制, 禁止别人去 new 这个实例!!
    private Singleton() {}

}
public class Demo16 {
    public static void main(String[] args) {
        Singleton s1 = Singleton.getInstance();
        Singleton s2 = Singleton.getInstance();
        System.out.println(s1 == s2);
        // Singleton s3 = new Singleton();
        // System.out.println(s1 == s3);
    }
}
